﻿namespace My.Hydrator.Formatters
{
    using System.ComponentModel.Composition;
    using System.ComponentModel.DataAnnotations;
    using My.Hydrator.Helpers;

    [Export(typeof(IDataTypeFormatter))]
    public class EmailDataTypeFormatter : BaseDataTypeFormatter, IDataTypeFormatter
    {
        private readonly string domain;

        public EmailDataTypeFormatter()
            : this("HYDRATOR.HY")
        {
        }

        public EmailDataTypeFormatter(string domain)
        {
            this.domain = domain;
        }

        public virtual DataTypeAttribute FormatterDataType
        {
            get { return new DataTypeAttribute(DataType.EmailAddress); }
        }

        public virtual object GetFormat()
        {
            var name = Lookups.AmericanNames[this.Random.Next(0, Lookups.AmericanNames.Count - 1)];
            var lastname = Lookups.AmericanLastNames[this.Random.Next(0, Lookups.AmericanLastNames.Count - 1)];
            return string.Format("{0}.{1}@{2}", name, lastname, this.domain);
        }
    }
}
